<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;

class Login extends Controller{

    public function login(){
        $data = input('post.');
        if(empty($data)){
            if(!empty($_SESSION['jmsm_admin']['uid'])){
                $this -> redirect('/admin/index/index');
            }
            return view();
        }else{
            $data['password'] = encryptPass($data['password']);
            $data['status'] = 1;
            $result = db('user') -> where($data) -> find();
            if(empty($result)){
                $this -> error('管理员不存在');
            }else{
                $_SESSION['jmsm_admin']['uid'] = $result['uid'];
                $_SESSION['jmsm_admin']['username'] = $result['username'];
                db('user') -> where('uid',$result['uid']) -> update(['last_log'=>time()]);
                $this -> success('登录成功，即将跳转到首页',url('admin/index/index'));
            }
        }

    }

    public function logout(){
        echo "退出登录";
    }


}